/** sqlite数据库初始化 */
import _DB from "./db.js";
import { DATABASE_NAME, DATABASE_PATH } from "./config.js";
import { createDiseaseTable, createOptionsTable } from "./init/disease.js";
import { createImagesTable } from "./init/files.js";
import { createDiseaseGradeTable } from './init/diseaseGrade.js'
import { createDiseaseContentTable } from './init/diseaseContent.js'
import { createDiseaseOrderLogTable } from './init/diseaseOrderLog.js'
import { createLastFillingRecordTable } from './init/lastFillingRecord.js'
import { createKeywordsTable } from './init/keywords.js'
import { createDiseaseStatusTable } from './init/diseaseStatus.js'
import { createDiseaseRepairTable } from './init/repairMeasures.js'
import { createGenTable, initGen } from './init/gen.js'
import {createDeletedImagesTable} from './init/deletedImages.js'
import {createStationsTable} from './init/stations.js'
import {createVideosTable} from "./init/video.js"
import {createDeletedVideosTable} from "./init/deletedVideos.js"

/** sqlite数据库相关操作的对象 */
export const DB = new _DB(DATABASE_NAME, DATABASE_PATH);

/** 处理初始化数据 */
export default () => {
	console.log('数据库初始化完成1111');
	return new Promise((resolve, reject) => {
		let promiseArray = [];
		
		// 初始化病害相关的表...
		
		promiseArray.push(createGenTable(DB));
		promiseArray.push(initGen(DB));
		promiseArray.push(createDiseaseTable(DB));
		promiseArray.push(createOptionsTable(DB));
		promiseArray.push(createImagesTable(DB));
		promiseArray.push(createDiseaseGradeTable(DB));
		promiseArray.push(createDiseaseContentTable(DB));
		promiseArray.push(createDiseaseOrderLogTable(DB));
		promiseArray.push(createLastFillingRecordTable(DB));
		promiseArray.push(createKeywordsTable(DB));
		promiseArray.push(createDiseaseStatusTable(DB));
		promiseArray.push(createDiseaseRepairTable(DB));
		promiseArray.push(createDeletedImagesTable(DB));
		promiseArray.push(createStationsTable(DB));
		promiseArray.push(createVideosTable(DB));
		promiseArray.push(createDeletedVideosTable(DB));
		// 创建表...
		Promise.all(promiseArray).then(() => {
			console.log('数据库初始化完成2222');
			resolve();
		}).catch((err) => {
			console.error(err)
			reject();
		});
	});
}

